Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Quickly create HTML tables from an ADO Recordset

Total Hit ( 5763)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


The ADO Recordset object exposes the GetString method, which returns the values in the Recordset into a formatted string. Here's its syntax:


res = GetString([StringFormat As StringFormatEnum = adClipString], _
  [NumRows As Long = -1], [ColumnDelimeter As String], _
  [RowDelimeter As String], [NullExpr As String]) As String

This method is often used to quickly export a Recordset into a comma-delimited file, even though this approach has several flaws (for example, you can't put quotes around string values).
The GetString method, however, turns to be very handy when generating HTML tables based on an ADO Recordset. The trick is to use the correct delimiters for the table's cells and rows. Moreover, you must correctly complete the string with the opening tags for the first cell of the first row, and for the last cell of the last row. Here's an example of how to implement this technique:

Click here to copy the following block
Dim rs, tmp
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "publishers", "DSN=pubs"

' open the table (you can set all the necessary attributes here)
Response.Write "<TABLE BORDER=1>

' convert the recordset to a table
tmp = rs.GetString( , , "
</TD><TD>", "</TD></TR><TR><TD>", "&nbsp;")
' to complete the conversion you must add the opening TR and TD tags
' for the very first cell, and drop the closing TD and TR tags
' after the very last cell
Response.Write "
<TR><TD>" & Left(tmp, Len(tmp) - 8)
' close the table
Response.Write "
</TABLE>"

Note that you must pass the HTML notation for "space", that is " ", in the last argument to GetString. If you don't do so, Null values will not produce any table cell.


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.